﻿using B.S.BaseData.Api.Read.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Read.CommandHandler.GoodsCommandHandler
{
    public class GoodscultivationCompanyCommandHandler : IRequestHandler<GoodscultivationCompanyCommand, APIResult<GoodscultivationCompany>>
    {
        private readonly IBaseRepository<GoodscultivationCompany> _scultivationCompanybaseRepository;
        public GoodscultivationCompanyCommandHandler(IBaseRepository<GoodscultivationCompany> scultivationCompanybaseRepository)
        {
            _scultivationCompanybaseRepository = scultivationCompanybaseRepository;
        }
        public async Task<APIResult<GoodscultivationCompany>> Handle(GoodscultivationCompanyCommand request, CancellationToken cancellationToken)
        {
            APIResult<GoodscultivationCompany> result=new APIResult<GoodscultivationCompany>();
            try
            {
                var list = await _scultivationCompanybaseRepository.GetValues(x => x.GoodsId == request.Id);
                result.Data = list;
                result.Msg = "企业信息显示成功";
                result.Code = ApiEnum.Success;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Msg = "企业信息显示失败";
                result.Code = ApiEnum.Fail;
                return await Task.FromResult(result);
            }

        }
    }
}
